home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 1155 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.5 KB  |  57 lines

  1. Path: news.kth.se!news
  2. From: Anders Olsson <aolsson@struct.kth.se>
  3. Newsgroups: comp.lang.c++
  4. Subject: OO design issue
  5. Date: 9 Jan 1996 13:06:43 GMT
  6. Message-ID: <4ctp93$2gu@news.kth.se>
  7. NNTP-Posting-Host: lotus.ce.kth.se
  8. Mime-Version: 1.0
  9. Content-Type: text/plain; charset=iso-8859-1
  10. Content-Transfer-Encoding: 8bit
  11.  
  12. I accidently posted the last message before I got to my point
  13. (never write messages in a window where you have a "Post it" keycombination:-)
  14.  
  15. I'll try again:
  16.  
  17.  I have some questions about how to design relations between a class and
  18.  its member classes.
  19.  
  20.  I can simplify my problem to the following three classes:
  21.  
  22.  class Node
  23.  {
  24.  public:
  25.     double GetXCoordinate();
  26.  private:
  27.     double XCoordinate; 
  28.  };
  29.  
  30.  class Triangle
  31.  {
  32.  public:
  33.     double CalculateArea();
  34.  private:
  35.     int nNodeIndex[3]; // Index into node vector
  36.  };
  37.  
  38.  class TrianglesAndNodes
  39.  {
  40.    double GetXCoordinate(int NodeNr);
  41.  private:
  42.     vector<Node>     NodeVector;   
  43.     vector<Triangle> TriangleVector;
  44.  };
  45.  
  46. The TrianglesAndNodes class is a world of nodes and triangles, and it contains two vectors of Node:s, and Triangle:s.
  47. The Triangle has a method that calculates its own area.
  48. However, it has only information about the index of the nodes it is connected to.
  49. So to get the necessary coordinates the Triangle instance can use the GetXCoordinate method,
  50. defined in TrianglesAndNodes. The problem is how to reach the TrianglesAndNodes instance
  51. from the Triangle instance.
  52. Is there a recommended way to do this is?
  53.  
  54. ---
  55. Anders Olsson
  56. Stockholm, Sweden
  57.